package cn.wolfcode.luowowo.website;

import cn.wolfcode.luowowo.website.interceptor.CheckLoginInterceptor;
import cn.wolfcode.luowowo.website.util.UserParamResolve;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * 这里我们重写那个配置类添加拦截器
 */
@SpringBootApplication
public class WebSite implements WebMvcConfigurer{
    @Autowired
    private CheckLoginInterceptor checkLoginInterceptor;
    @Autowired
    private UserParamResolve userParamResolve;


    public static void main(String[] args) {

        SpringApplication.run(WebSite.class, args);
    }

    /**
     * 配置拦截器的拦截路径和排除路径
     * @param registry
     */

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(checkLoginInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/regist.html")
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/styles/**");

    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {

        resolvers.add(userParamResolve);
    }

}



